<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="entity.Category,entity.Product,entity.User" %>
<html>
<head>
    <title>个人收藏</title>
    <link href="../css/wishListCss.css" rel="stylesheet">
</head>
<body>
    <jsp:include page="${pageContext.request.contextPath}/page/Header.jsp"></jsp:include>
    <div id="nav">
        <nav class="breadcrumb" style="padding-left:100px;">
            <a class="breadcrumb-item" href="/">首页</a>
            <span class="breadcrumb-item">分类</span>
            <span class="breadcrumb-item active">个人收藏</span>
        </nav>
    </div>
    <c:if test="${sessionScope.wishList != null}">
        <div id="wishList" class="container">
            <c:forEach items="${sessionScope.wishList}" var="wishList" varStatus="index">
                <div class="wishItem" >
                    <h4>${wishList.key}</h4>
                    <div class="wishProduct">
                        <table class="table table-striped table-striped" style="table-layout: fixed !important;">
                            <thead>
                            <tr>
                                <th style="width:70%;">商品名称</th>
                                <th>库存数量</th>
                                <th>商品价格</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${wishList.value}" var="value">
                                <tr>
                                    <td>
                                        <div style="display: flex;">
                                            <div>
                                                <img src="${value.getDefaultImg()}" style="width:50px;height:50px;" >
                                            </div>
                                            <div class="productTitle">
                                                <span class="productTitle"><a href="/service/product_details?productId=${value.getProductId()}">${value.getProductName()}</a></span>
                                            </div>
                                        </div>
                                    </td>
                                    <td>${value.getStore()} 件</td>
                                    <td>￥${value.getPrice()}</td>
                                    <td> <button type="button" class="btn btn-light" onclick="deleteProduct(${value.getProductId()},${sessionScope.user.getId()})">删除</button> </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </div>
                <hr>
            </c:forEach>
        </div>
    </c:if>
    <c:if test="${empty sessionScope.wishList}">
        <div class="container">
            <h2>收藏夹暂无数据，<a href="/">快去添加吧....</a></h2>
        </div>
    </c:if>
    <div class="tipBox"></div>
<script src="../js/tip.js"></script>
<script>
    function deleteProduct(productId,userId){
        $.get('/service/wish_delete?productId=' + productId + '&userId=' + userId,function(data){
                console.log(data);
        });
    }
</script>
</body>
</html>
